package dieciLuglio;

import java.awt.Image;
import java.awt.Toolkit;
import java.io.*;
import java.net.*;

import com.apple.eawt.Application;


public class ServerRisto {
	static int threadAttivi=0;
	private boolean statoServer;
	
	public boolean getStatoServer(){
		return statoServer;
	}
	
	public ServerRisto() {
		Application application= Application.getApplication();
		Image image=Toolkit.getDefaultToolkit().getImage(getClass().getResource("foto/Snome.png"));
		application.setDockIconImage(image);
		ServerSocket server=null;
		try{
			server = new ServerSocket(3001);
			System.out.println("server partito");
			while(true){
				System.out.println("in attesa di connesioni");
				Socket clientSocket=server.accept();
				threadAttivi++;
				System.out.println(clientSocket);

				try {
					System.out.println("Server: avvioServerThread");
					ServerThread a=new ServerThread(clientSocket);
				} catch(IOException e) { 
					clientSocket.close(); 
					threadAttivi--;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}catch(IOException e){
			System.err.println(e);
		}
		try {
			server.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	
	
	public static void main(String [] args) {
		ServerRisto a=new ServerRisto();
	}
	
}
